import store from 'store/index'
import { jointLand } from 'lib/until'
import {
  tracker
} from 'lib/analytics'

const Home = () => import("view/Index") // 首页
const ruleDetail = () => import('view/detail') // 详情
const information = () => import('view/acdetail') // 详情
const Installer = () => import("view/installer/Index") // 数字平台
// 云课堂
const cloudRoom = () => import('view/installer/class/index')
const CNotice = () => import('view/installer/class/notice')
const CLive = () => import('view/installer/class/live')
const CDown = () => import('view/installer/class/down')
const CSeach = () => import('view/installer/class/search')
const BIM = () => import('view/installer/bim/index')
const video = () => import('view/installer/bim/live')

const Association = () => import('view/association/index')
// const About = () => import('view/association/about')
const AcProduction = () => import('view/association/about/production')
const Corganization = () => import('view/association/about/organization')
const Ccontact = () => import('view/association/about/contact')

const Regulations = () => import('view/regulations/index')
const Rcountry = () => import('view/regulations/country')
const Rannouncement = () => import('view/regulations/announcement')
const Rlocal = () => import('view/regulations/local')

const Expert = () => import('view/expert/index')
const DataBase = () => import('view/expert/database')
const Commiter = () => import('view/expert/commiter')
const Committee = () => import('view/expert/committee')

const Party = () => import('view/party/index')
const Raffairs = () => import('view/party/affairs')
const Rbuild = () => import('view/party/build')

const Train = () => import('view/train/index')
const Notice = () => import('view/train/notice')
const Cloud = () => import('view/train/cloud')

const Innovation = () => import('view/innovation/index')
const Itechnological = () => import('view/innovation/technological')
const Iproject = () => import('view/innovation/project')
const Istar = () => import('view/innovation/star')
const ITemplate = () => import('view/innovation/template')

const Cost = () => import('view/installer/cost/index')
const cRules = () => import('view/installer/cost/rules')
const cPrice = () => import('view/installer/cost/price')
const cInformation = () => import('view/installer/cost/information')

const Cassess = () => import('view/installer/assess')

const Evaluation = () => import('view/installer/evaluation/index')
const eNotice = () => import('view/installer/evaluation/notice')
const eManage = () => import('view/installer/evaluation/manage')
const eDown = () => import('view/installer/evaluation/down')
const eSeach = () => import('view/installer/evaluation/search')

const CCompletion = () => import('view/installer/completion/index')
const CCase = () => import('view/installer/completion/case')
const CRules = () => import('view/installer/completion/rules')
const CTable = () => import('view/installer/completion/table')

const Promotion = () => import('view/installer/promotion/index')
const PNotice = () => import('view/installer/promotion/notice')
const PRules = () => import('view/installer/promotion/rules')
const PResuslts = () => import('view/installer/promotion/results')

const IRecord = () => import('view/installer/record/index')
const INotice = () => import('view/installer/record/notice')
const IRules = () => import('view/installer/record/rules')
const ISearch = () => import('view/installer/record/search')
const Excellence = () => import('view/installer/excellence/index')

const Vip = () => import('view/vip/index')

let routes = [
  {
    path: "/",
    redirect: '/home'
  }, {
    path: "/home",
    name: 'home',
    component: Home,
    meta: {
      title: "首页"
    }
  }, {
    path: '/fold/:id',
    component: ruleDetail
  }, {
    path: '/information',
    component: information
  }, {
    path: '/excellence/index',
    component: Excellence
  }, {
    path: '/template',
    component: ITemplate
  }, {
    path: '/assess',
    component: Cassess
  }, {
    path: '/record',
    name: 'IRecord',
    redirect: '/record/rules',
    component: IRecord,
    children: [{
      path: 'rules',
      name: 'IRules',
      component: IRules
    }, {
      path: 'notice',
      name: 'INotice',
      component: INotice
    }, {
      path: 'search',
      name: 'ISearch',
      component: ISearch
    }]
  }, {
    path: '/promotion',
    name: 'promotion',
    redirect: '/promotion/rules',
    component: Promotion,
    children: [{
      path: 'rules',
      name: 'PRules',
      component: PRules
    }, {
      path: 'notice',
      name: 'PNotice',
      component: PNotice
    }, {
      path: 'results',
      name: 'PResuslts',
      component: PResuslts
    }]
  }, {
    path: '/completion',
    name: 'CCompletion',
    redirect: '/completion/rules',
    component: CCompletion,
    children: [{
      path: 'rules',
      name: 'CRules',
      component: CRules
    }, {
      path: 'case',
      name: 'CCase',
      component: CCase
    }, {
      path: 'table',
      name: 'CTable',
      component: CTable
    }]
  }, {
    path: '/cost',
    name: 'cost',
    component: Cost,
    redirect: '/cost/rules',
    children: [{
      path: 'rules',
      name: 'cRules',
      component: cRules
    }, {
      path: 'price',
      name: 'cPrice',
      component: cPrice
    }, {
      path: 'information',
      name: 'cInformation',
      component: cInformation
    }]
  }, {
    path: '/evaluation',
    name: 'Ievaluation',
    redirect: '/evaluation/notice',
    component: Evaluation,
    children: [{
      path: 'notice',
      name: 'eNotice',
      component: eNotice
    }, {
      path: 'manage',
      name: 'emanage',
      component: eManage
    }, {
      path: 'down',
      name: 'eDown',
      component: eDown
    }, {
      path: 'seach',
      name: 'eSeach',
      component: eSeach
    }]
  }, {
    path: '/vip',
    component: Vip
  }, {
    path: "/install",
    name: 'install',
    component: Installer,
    meta: {
      title: "数字网络平台"
    }
  }, {
    path: '/cloud',
    name: 'Icloudroom',
    redirect: '/cloud/notice',
    component: cloudRoom,
    children: [{
      path: 'notice',
      name: 'cNotice',
      component: CNotice
    }, {
      path: 'live',
      name: 'live',
      component: CLive
    }, {
      path: 'down',
      name: 'cDown',
      component: CDown
    }, {
      path: 'seach',
      name: 'cSeach',
      component: CSeach
    }]
  }, {
    path: '/bim',
    name: 'bim',
    component: BIM
  }, {
    path: '/video',
    name: 'video',
    component: video
  }, {
    path: '/association',
    name: 'association',
    redirect: '/association/product',
    component: Association,
    children: [{
      path: 'product',
      name: 'acProduct',
      component: AcProduction
    }, {
      path: 'organization',
      name: 'Corganization',
      component: Corganization
    }, {
      path: 'contact',
      name: 'Ccontact',
      component: Ccontact
    }]
  }, {
    path: '/regulations',
    name: 'regulations',
    redirect: '/regulations/product',
    component: Regulations,
    children: [{
      path: 'country',
      name: 'country',
      component: Rcountry
    }, {
      path: 'local',
      name: 'Rlocal',
      component: Rlocal
    }, {
      path: 'announcement',
      name: 'Rannouncement',
      component: Rannouncement
    }]
  }, {
    path: '/expert',
    name: 'expert',
    redirect: '/expert/committee',
    component: Expert,
    children: [{
      path: 'dataBase',
      name: 'dataBase',
      component: DataBase
    }, {
      path: 'commiter',
      name: 'commiter',
      component: Commiter
    }, {
      path: 'committee',
      name: 'committee',
      component: Committee
    }]
  }, {
    path: '/party',
    name: 'party',
    redirect: '/party/affairs',
    component: Party,
    children: [{
      path: 'affairs',
      name: 'Raffairs',
      component: Raffairs
    }, {
      path: 'build',
      name: 'Rbuild',
      component: Rbuild
    }]
  }, {
    path: '/train',
    name: 'train',
    redirect: '/train/notice',
    component: Train,
    children: [{
      path: 'notice',
      name: 'notice',
      component: Notice
    }, {
      path: 'cloud',
      name: 'cloud',
      component: Cloud
    }]
  }, {
    path: '/innovation',
    name: 'Innovation',
    redirect: '/innovation/technological',
    component: Innovation,
    children: [{
      path: 'technological',
      name: 'Itechnological',
      component: Itechnological
    }, {
      path: 'project',
      name: 'Iproject',
      component: Iproject
    }, {
      path: 'star',
      name: 'Istar',
      component: Istar
    }]
  }
]
export const beforeEach = (to, from, next) => {
  if (to.name != from.name && window.navigator.onLine) {
    store.commit('SHOWLOADINGFLAG', true)
  } else if (!window.navigator.onLine) {
    store.commit('UPDATETOAST', {
      msg: '网络请求失败，请检查您的网络设置'
    })
    setTimeout(function () {
      store.commit('UPDATETOAST', {
        msg: ''
      }) // 此处需要手动添加一个定时器2s以后隐藏toast
    }, 2000)
  }
  // 校验判断,需要登录的路由
  if (to.matched.some(record => record.meta.requiresAuth) && !tracker.getToken()) {
    next(false)
    jointLand()
  } else {
    next()
  }
}
export const afterEach = route => {
  store.commit('SHOWLOADINGFLAG', false)
  document.body.scrollTop = document.documentElement.scrollTop = 0
}
export default routes
